package com.soulless.annotation;

import java.lang.annotation.*;
import java.util.Arrays;

/**
 * <p>
 * 注解继承
 * </p>
 *
 * @author zenglei
 * @date 2022/04/22/ 14:47
 */
public class AnnotationDemo {

    public static void main(String... args) {
        A instanceA = new B();
        System.out.println("已使用的@Inherited注解:" + Arrays.toString(instanceA.getClass().getAnnotations()));

        C instanceC = new D();

        System.out.println("没有使用的@Inherited注解:" + Arrays.toString(instanceC.getClass().getAnnotations()));
    }

    /**
     * 运行结果:
     已使用的@Inherited注解:[@com.zejian.annotationdemo.DocumentA()]
     没有使用的@Inherited注解:[]
     */

}

@Inherited
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface DocumentA {
}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface DocumentB {
}

@DocumentA
class A {
}

class B extends A {
}

@DocumentB
class C {
}

class D extends C {
}